package com.cnpinxi.controller.web.user;

import com.cnpinxi.controller.base.BaseController;
import com.cnpinxi.def.Constant;
import com.cnpinxi.domain.User;
import com.cnpinxi.domain.UserAccount;
import com.cnpinxi.result.ResultObj;
import com.cnpinxi.service.UserAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by Baggio on 2018-3-6.
 */
@RequestMapping("/user")
@Controller
public class UserAccountController  extends BaseController {
@Autowired
    UserAccountService userAccountService;
    @RequestMapping(value = "/getUserAccountList")
    @ResponseBody
    public String getUserAccountList(HttpServletRequest request) {
        ResultObj resultObj = new ResultObj();
        resultObj.setCode(ResultObj.CODE_SUCCESS);
        try {

            HttpSession session = request.getSession();
         User user=  (User) session.getAttribute(Constant.SESSION_KEY_USER_LOGIN);
            List<UserAccount> userAccountList=userAccountService.getUserAccountList(user);
            resultObj.setData(userAccountList);
            resultObj.setMsg("操作成功！");
        } catch (Exception e) {
            resultObj.setCode(ResultObj.CODE_FAIL);
            resultObj.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return resultObj.toJson();
    }
}
